package com.yidian.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yidian.pojo.seckill.SeckillGoods;
import com.yidian.server.seckill.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

/**
 * @author whb
 * @create 2021-10-08 09:59
 * @desciption 秒杀商品Service实现类
 */
@Service
public class SeckillGoodsServiceImpl implements SeckillGoodsService {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 根据时间字符串从redis缓存中读取秒杀商品列表
     * @param time
     * @return
     */
    @Override
    public List<SeckillGoods> list(String time) {
        return redisTemplate.boundHashOps("SeckillGoods_"+time).values();
    }

    /**
     * 查询秒杀商品
     * @param time 时间区间
     * @param id 秒杀商品的ID
     * @return
     */
    @Override
    public SeckillGoods queryGood(String time, Long id) {
        return (SeckillGoods) redisTemplate.boundHashOps("SeckillGoods_"+time).get(id);
    }
}
